package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @Author: xiongzhenhui
 * @Create: 2025/8/8 15:23
 * @Version: 1.0
 */
@RestController
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;
    @RequestMapping("/getOrderInfoByZj")
    public JSONObject getOrderInfoByZj(){
        List<Map> list = orderInfoService.getOrderInfoByZj();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray columns = new JSONArray();
            JSONObject col2 = new JSONObject();
            col2.put("name","章节名称");
            col2.put("id","chapter_name");
            columns.add(col2);

            JSONObject col3 = new JSONObject();
            col3.put("name","播放次数");
            col3.put("id","bf_num");
            columns.add(col3);

            JSONObject col4 = new JSONObject();
            col4.put("name","播放时长");
            col4.put("id","bf_time");
            columns.add(col4);

            JSONObject col5 = new JSONObject();
            col5.put("name","观看人数");
            col5.put("id","gk_people");
            columns.add(col5);

            JSONObject col6 = new JSONObject();
            col6.put("name","人均观看时长");
            col6.put("id","avg_time");
            columns.add(col6);

        data.put("columns",columns);
        JSONArray rows = new JSONArray();
        for (Map map : list) {
            JSONObject row = new JSONObject();
            row.put("chapter_name",map.get("chapter_name"));
            row.put("bf_num",map.get("bf_num"));
            row.put("bf_time",map.get("bf_time"));
            row.put("gk_people",map.get("gk_people"));
            row.put("avg_time",map.get("avg_time"));
            rows.add(row);
        }
        data.put("rows",rows);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getorderInfoByCj")
    public JSONObject getorderInfoByCj(){
        List<Map> list = orderInfoService.getorderInfoByCj();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray data = new JSONArray();
        for (Map map : list) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("fs"));
            jsonObject1.put("value",map.get("num"));
            data.add(jsonObject1);
        }

        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getOrderInfoByDq")
    public JSONObject getOrderInfoByDq(){
        List<Map> list = orderInfoService.getOrderInfoByDq();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray mapData = new JSONArray();
        for (Map map : list) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("origin_amount"));
            JSONArray tooltipValues = new JSONArray();
            tooltipValues.add(map.get("order_people"));
            tooltipValues.add(map.get("order_num"));
            jsonObject1.put("tooltipValues",tooltipValues);
            mapData.add(jsonObject1);

        }
        data.put("mapData",mapData);
        data.put("valueName","订单总额");

        JSONArray tooltipNames = new JSONArray();
        tooltipNames.add("下单人数");
        tooltipNames.add("订单数");
        data.put("tooltipNames",tooltipNames);

        JSONArray tooltipUnits = new JSONArray();
        tooltipUnits.add("人");
        tooltipUnits.add("个");
        data.put("tooltipUnits",tooltipUnits);

        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getOrderInfoJe")
    public JSONObject getOrderInfoJe(){
        List<Map> list = orderInfoService.getOrderInfoJe();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        for (Map map : list) {
            jsonObject.put("data",map.get("final_amount"));
        }

        return jsonObject;
    }
}
